/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tampilan;

import java.awt.Color;
import java.awt.Font;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//import java.io.BufferedWriter;
//import java.io.FileWriter;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.*;
import javax.swing.JPanel;
import kasus1pendaftaranyudisium.Cek;
import kasus1pendaftaranyudisium.PengendaliPemeriksaanYudisium;
import kasus1pendaftaranyudisium.PengendaliPendaftaranYudisium;
import kasus1pendaftaranyudisium.ViewtPeriksaYudisium;

/**
 *
 * @author sonny
 */
public class PanelPeriksaYudisium extends JPanel {

    private JLabel labelPanel;
    private JLabel labelNim;
    private JTextField textNim;
    private JButton tombolPeriksa;
    private JButton tombolBatal;

    public PanelPeriksaYudisium() {

        setLayout(null);

        labelPanel = new JLabel("Panel Periksa Yudisium");
        labelPanel.setBounds(190, 15, 200, 40);
        add(labelPanel);

        labelNim = new JLabel("Nim");
        labelNim.setBounds(50, 90, 100, 50);
        add(labelNim);

        textNim = new JTextField();
        textNim.setBounds(150, 100, 270, 32);
        textNim.setBackground(Color.WHITE);
        add(textNim);

        tombolPeriksa = new JButton("Periksa");
        tombolPeriksa.setBounds(160, 180, 110, 30);
        add(tombolPeriksa);
        tombolPeriksa.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                tombolPeriksaAction();
            }
        });

        tombolBatal = new JButton("Batal");
        tombolBatal.setBounds(300, 180, 110, 30);
        add(tombolBatal);
        tombolBatal.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                tombolBatalAction();
            }
        });

        setVisible(true);
    }

    public void tombolPeriksaAction() {
        if (textNim.getText().isEmpty()) {
            try {
                throw new Exception("Nim harus diisi!!!");
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
                Logger.getLogger(PanelPeriksaYudisium.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            Cek pe = new Cek();
            JDialog testFrame = new JDialog();
            pe.setNim(textNim.getText());
            PengendaliPemeriksaanYudisium.periksaDataYudisium(pe);
            if (PengendaliPendaftaranYudisium.DAFTAR_MAHASISWA.isEmpty()) {
                JOptionPane.showMessageDialog(null, "Tidak Terdaftar");
            } else {
                ViewtPeriksaYudisium test = new ViewtPeriksaYudisium(PengendaliPendaftaranYudisium.DAFTAR_MAHASISWA);
                testFrame.getContentPane().add(test);
                testFrame.setSize(1367, 765);
                testFrame.setVisible(true);
                testFrame.setTitle("Panel Periksa Yudisium");
            }
        }
    }

    public void tombolBatalAction() {
        System.exit(0);
    }
}
